package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.CommissionAuthoritySearchVo;
import com.zhijian.medical.entity.vo.request.PersonCommissionAuthoritySaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.PersonCommissionAuthoritySearchVo;
import com.zhijian.medical.entity.vo.response.CommissionAuthorityVo;
import com.zhijian.medical.entity.vo.response.PersonCommissionAuthorityVo;
import com.zhijian.medical.service.CommissionAuthorityService;
import com.zhijian.medical.service.PersonCommissionAuthorityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员-分级授权书 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-03-28 17:07:47
 */
@Slf4j
@Controller
@Api(tags = "人员-分级授权书")
public class PersonCommissionAuthorityController {

    @Autowired
    private PersonCommissionAuthorityService service;

    @Autowired
    private CommissionAuthorityService commissionAuthorityService;

    /**
     * 新增or修改
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/person/commission/authority")
    @ApiOperation("新增or修改")
    public boolean saveOrUpdate(@RequestBody PersonCommissionAuthoritySaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.saveOrUpdate(param);
    }

    /**
     * 删除
     *
     * @param commissionAuthorityId
     * @return
     */
    @Response
    @DeleteMapping("/person/commission/authority/{commissionAuthorityId}")
    @ApiOperation("删除")
    public boolean delete(@ApiParam(name = "commissionAuthorityId", value = "项目名称id")
                          @PathVariable("commissionAuthorityId") Long commissionAuthorityId) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), commissionAuthorityId);
        service.deleteAllByCommissionAuthorityId(commissionAuthorityId);
        return true;
    }

    /**
     * 根据人员id列表查询，不分页
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/person/commission/authority/list")
    @ApiOperation("根据人员id列表查询，不分页")
    public List<PersonCommissionAuthorityVo> selectByCondition(@RequestBody(required = false) PersonCommissionAuthoritySearchVo param) {
        if (param == null)
            param = PersonCommissionAuthoritySearchVo.builder().build();
        return service.selectList(param);
    }

    /**
     * 查询所有的授权项目列表
     *
     * @return
     */
    @Response
    @GetMapping("/commission/authority/list")
    @ApiOperation("查询所有的授权项目列表")
    public List<CommissionAuthorityVo> selectCommissionAuthorityList() {
        return commissionAuthorityService.selectList(CommissionAuthoritySearchVo.builder()
                .build());
    }

}